<template>
  <div class="app-container">
    <div>
      <BasicBusiness ref="basicBusinessRef" />
    </div>
    <div style="padding: 50px">
      <Step ref="stepRef" />
    </div>
    <el-form
      ref="elForm"
      :model="formData"
      :rules="rules"
      size="medium"
      label-width="140px"
    >
      <el-form-item label="合同约定交付时间" prop="agreeDeliveryTime">
        <el-date-picker
          v-model="formData.agreeDeliveryTime"
          format="yyyy-MM-dd"
          value-format="yyyy-MM-dd"
          :style="{ width: '100%' }"
          placeholder="请选择合同约定交付时间"
          clearable
        ></el-date-picker>
      </el-form-item>
      <el-form-item label="是否需要后项采购" prop="isNeedDownProcurement">
        <el-select
          v-model="formData.isNeedDownProcurement"
          placeholder="请选择是否需要后项采购"
          clearable
          :style="{ width: '100%' }"
        >
          <el-option
            v-for="(item, index) in isNeedDownProcurementOptions"
            :key="index"
            :label="item.label"
            :value="item.value"
            :disabled="item.disabled"
          ></el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="计划交付时间" prop="planDeliveryTime">
        <el-date-picker
          v-model="formData.planDeliveryTime"
          format="yyyy-MM-dd"
          value-format="yyyy-MM-dd"
          :style="{ width: '100%' }"
          placeholder="请选择计划交付时间"
          clearable
        ></el-date-picker>
      </el-form-item>
      <el-form-item size="mini">
        <el-button type="primary" @click="submitForm">提交</el-button>
        <el-button @click="resetForm">重置</el-button>
      </el-form-item>
    </el-form>
  </div>
</template>
<script>
import BasicBusiness from "@/views/components/business/BasicBusiness.vue";
import Step from "@/views/components/business/Step.vue";
import { getProjectDetail, projectStart } from "@/api/project/index";
export default {
  components: { BasicBusiness, Step },
  props: [],
  data() {
    return {
      formData: {
        agreeDeliveryTime: null,
        isNeedDownProcurement: undefined,
        planDeliveryTime: null,
      },
      rules: {
        agreeDeliveryTime: [
          {
            required: true,
            message: "请选择合同约定交付时间",
            trigger: "change",
          },
        ],
        isNeedDownProcurement: [
          {
            required: true,
            message: "请选择是否需要后项采购",
            trigger: "change",
          },
        ],
        planDeliveryTime: [
          {
            required: true,
            message: "请选择计划交付时间",
            trigger: "change",
          },
        ],
      },
      isNeedDownProcurementOptions: [
        {
          label: "是",
          value: 1,
        },
        {
          label: "否",
          value: 2,
        },
      ],
    };
  },
  computed: {
    boId() {
      return this.$route.query.boId;
    },
    projectId() {
      return this.$route.query.projectId;
    },
  },
  watch: {},
  created() {},
  mounted() {
    this.loadData();
  },
  methods: {
    loadData() {
      this.$refs.basicBusinessRef.loadData(this.boId).then((res) => {});
      getProjectDetail(this.boId).then((res) => {
        ;
        this.stage = res.data.stage;
        this.$refs.stepRef.setStage(this.stage);
      });
    },
    submitForm() {
      this.$refs["elForm"].validate((valid) => {
        if (!valid) return;
        // TODO 提交表单

        projectStart({
          boId: this.boId,
          ...this.formData,
        }).then((res) => {
          this.$message({
            message: "操作成功",
            type: "success",
          });
          this.$router.replace("/implement/index");
        });
      });
    },
    resetForm() {
      this.$refs["elForm"].resetFields();
    },
  },
};
</script>
<style></style>
